<template>
    <div class="main-content clearfix">
        <!--商品图片-->
        <Zoom :goodsImg="goodsInfo.picture"></Zoom>
        <ul class="shop-information">
            <li class="name-wrapper clearfix">{{ goodsInfo.goodsName }}</li>
            <li class="describe-wrapper clearfix">{{ goodsInfo.description }}</li>
            <li class="seller-wrapper clearfix">{{ $route.query.seller }}</li>
            <li class="inventory">
                剩余
                <em style="font-size:18px;color: #ff6700;">{{ goodsInfo.inventory }}</em>
                件
            </li>
            <li class="price-wrapper clearfix">
                <div class="price">{{ Number(goodsInfo.unitPrice).toFixed(2) }}</div>元
            </li>
            <li>
                <num-box :maxNum="goodsInfo.inventory" @changeNum="changeNum"></num-box>
                <div class="total-price">
                    总计:
                    <em style="font-size:28px;color: #ff6700;">{{totalPrice}}</em>
                    元
                </div>
            </li>
            <div class="button-wrapper clearfix">
                <div class="buy-button" @click="addShopCart">加入购物车</div>
                <div class="like-button">
                    <i class="iconfont icon-xihuan">喜欢</i>
                </div>
            </div>
        </ul>
    </div>
</template>

<script>
import Zoom from "@/pages/Detail/Main/Content/Zoom";
import numBox from "@/components/numBox";
export default {
    data() {
        return {
            nums: 1,
        };
    },
    methods: {
        changeNum(val){
            this.nums += val;
        },
        async addShopCart(){
            let goodsItem = {
                goodId:this.goodsInfo.goodsId,
                goodsNum:this.nums
            };
            this.$bus.$emit("addShopCart",goodsItem);
        }
    },
    computed: {
        totalPrice() {
            let price = Number(this.goodsInfo.unitPrice).toFixed(2);
            return Number(price * this.nums).toFixed(2);
        },
    },
    components: {
        Zoom,
        numBox,
    },
    props: ["goodsInfo"],
};
</script>

<style lang="less" scoped>
.main-content {
    width: 1200px;
    margin: 0 auto;
    padding: 50px 0 30px;
    border-bottom: 1px solid rgb(224, 224, 224);
    display: flex;
    justify-content: space-between;
}

/*设置图片和信息的位置*/
/* 设置放大镜组件的位置 */
#zoom {
    /* margin: 50px 0 ; */
}

.main-content .shop-information {
    width: 600px;
    margin: 10px 0 0 100px;
    /* float: right; */
}
/*设置各个信息的样式*/
.shop-information .name-wrapper {
    font-size: 24px;
    font-weight: 400;
    height: 36px;
    line-height: 36px;
}

.shop-information .describe-wrapper {
    color: #b0b0b0;
    margin-top: 15px;
}

.shop-information .seller-wrapper {
    color: rgb(91, 81, 69);
    margin-top: 15px;
}
.inventory {
    margin-top: 15px;
}

.total-price{
    margin-top: 15px;
}

.price-wrapper {
    font-size: 18px;
    color: #ff6700;
    margin-top: 15px;
    border-bottom: 1px solid rgb(224, 224, 224);
    padding-bottom: 20px;
}

.price-wrapper > * {
    float: left;
}

/*设置两个按键的样式*/
.button-wrapper {
    border-top: 1px solid rgb(224, 224, 224);
    margin-top: 20px;
    padding-top: 20px;
}

.button-wrapper > * {
    float: left;
}

.button-wrapper .buy-button {
    box-sizing: border-box;
    width: 300px;
    height: 54px;
    background-color: rgb(255, 103, 0);
    margin-right: 10px;
    color: white;
    line-height: 52px;
    font-size: 16px;
    text-align: center;
    transition: background-color 0.3s;
}

.button-wrapper .buy-button:hover {
    background-color: rgb(242, 88, 7);
}

.button-wrapper .like-button {
    box-sizing: border-box;
    width: 142px;
    height: 54px;
    background-color: rgb(176, 176, 176);
    color: white;
    line-height: 52px;
    font-size: 16px;
    text-align: center;
    transition: background-color 0.3s;
}

.button-wrapper .like-button:hover {
    background-color: rgb(117, 117, 117);
}
</style>